package cn.ad.server.web.filter.bid;

import cn.ad.server.web.spring.service.actions.context.BidContext;
import cn.ad.server.domain.ad.Strategy;
import cn.ad.server.domain.ad.StrategyDeviceMap;
import cn.ad.server.domain.enumration.Connection;
import cn.ad.server.domain.enumration.OS;
import cn.ad.server.domain.enumration.Operator;

import java.util.List;

/**
 * 设备定向
 * @author wangwei
 *
 */
public class DeviceMatcher implements BidMatcherChain {

	@Override
	public boolean match(Strategy strategy, BidContext context) {
		StrategyDeviceMap deviceTargert = strategy.getDeviceTargert();
		if(deviceTargert==null){			
			return true;
		}
		
		List<Connection> connectTypeList = deviceTargert.getConnectTypeList();
		Connection connection = Connection.connectionMap.get(context.getConnType());
		if(connectTypeList!=null&&connectTypeList.size()>0&&!connectTypeList.contains(connection)){
			return false;
		}
		
		List<OS> osList = deviceTargert.getOsList();
		OS os = OS.osMap.get(context.getOs());
		if (osList != null && osList.size() > 0 && !osList.contains(os)) {
			return false;
		}
		List<Operator> operatorList = deviceTargert.getOperatorList();
		Operator operator = Operator.operatorMap.get(context.getMobOps());
		if(operatorList!=null&&operatorList.size()>0&&!operatorList.contains(operator)){
			return false;
		}
		return true;
	}

}
